package com.example.springbootfirst.entity;

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.UUIDGenerator;

import java.io.Serializable;

/**
 * created by Morgan on 2021/10/1
 */
public class JpaUuidGenerator extends UUIDGenerator {
    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
        Serializable serializable = super.generate(session,object);
        if (serializable instanceof String) {
            String id = (String) serializable;
            return id.replace("-","").toUpperCase();
        }
        return serializable;
    }
}
